.TH std::numpunct 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::numpunct \- std::numpunct

.SH Synopsis
   Defined in header <locale>
   template< class CharT >
   class numpunct;

   The facet std::numpunct encapsulates numeric punctuation preferences. Stream I/O
   operations use std::numpunct through std::num_get and std::num_put for parsing
   numeric input and formatting numeric output.

   The numbers that are supported by std::numpunct have the format described below.
   Here digit represents the radix set specified by the fmtflags argument value,
   thousands-sep and decimal-point are the results of thousands_sep() and
   decimal_point() functions respectively. The format of integer values is as follows:

 integer     ::= [sign] units
 sign        ::= plusminus
 plusminus   ::= '+' | '-'
 units       ::= digits [thousands-sep units]
 digits      ::= digit [digits]

   The number of digits between the thousand-seps (maximum size of digits) is specified
   by the result of grouping().

   The format of floating-point values is as follows:

 floatval    ::= [sign] units [decimal-point [digits]] [e [sign] digits] |
                 [sign]        decimal-point  digits   [e [sign] digits]
 e           ::= 'e' | 'E'

   std-numpunct-inheritance.svg

                                   Inheritance diagram

.SH Specializations

   The standard library is guaranteed to provide the following specializations (they
   are required to be implemented by any locale object):

   Defined in header <locale>
   std::numpunct<char>    provides equivalents of the "C" locale preferences
   std::numpunct<wchar_t> provides wide character equivalents of the "C" locale
                          preferences

.SH Member types

   Member type Definition
   char_type   CharT
   string_type std::basic_string<CharT>

.SH Member functions

   constructor   constructs a new numpunct facet
                 \fI(public member function)\fP
   destructor    destructs a numpunct facet
                 \fI(protected member function)\fP
   decimal_point invokes do_decimal_point
                 \fI(public member function)\fP
   thousands_sep invokes do_thousands_sep
                 \fI(public member function)\fP
   grouping      invokes do_grouping
                 \fI(public member function)\fP
   truename      invokes do_truename or do_falsename
   falsename     \fI(public member function)\fP

.SH Protected member functions

   do_decimal_point provides the character to use as decimal point
   \fB[virtual]\fP        \fI(virtual protected member function)\fP
   do_thousands_sep provides the character to use as thousands separator
   \fB[virtual]\fP        \fI(virtual protected member function)\fP
   do_grouping      provides the numbers of digits between each pair of thousands
   \fB[virtual]\fP        separators
                    \fI(virtual protected member function)\fP
   do_truename      provides the string to use as the name of the boolean true and
   do_falsename     false
   \fB[virtual]\fP        \fI(virtual protected member function)\fP

.SH Member objects

   static std::locale::id id id of the locale
                             \fI(public member object)\fP

.SH Example

   The following example changes the string representations of true and false:


// Run this code

 #include <iostream>
 #include <locale>

 struct french_bool : std::numpunct<char>
 {
     string_type do_truename() const override { return "vrai"; }
     string_type do_falsename() const override { return "faux"; }
 };

 int main()
 {
     std::cout << "default locale: "
               << std::boolalpha << true << ", " << false << '\\n';
     std::cout.imbue(std::locale(std::cout.getloc(), new french_bool));
     std::cout << "locale with modified numpunct: "
               << std::boolalpha << true << ", " << false << '\\n';
 }

.SH Output:

 default locale: true, false
 locale with modified numpunct: vrai, faux

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

     DR    Applied to           Behavior as published               Correct behavior
   LWG 338 C++98      the sign token allowed an optional         removed the whitespace
                      whitespace following + or -

.SH See also

   numpunct_byname creates a numpunct facet for the named locale
                   \fI(class template)\fP
